<?php
/* --------------------------------------------------------------
   PropertiesValuesContentView.inc.php 2012-02-14 tb@gambio
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2011 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/

class PropertiesValuesContentView extends ContentView
{
	
	function PropertiesValuesContentView() 
	{
		$this->v_coo_properties_admin_control = MainFactory::create_object('PropertiesAdminControl');
	}
	
	function get_html($p_param)
	{
		$t_html_output = '';

		$c_properties_id = (int)$p_param['properties_id'];
		$c_properties_values_id = (int)$p_param['properties_values_id'];
		if($p_language_id !== false) $c_language_id = (int)$p_language_id; else $c_language_id = false;
		
		if($c_properties_values_id == ""){
			$t_propertie_value_names_array = array();
			$t_sort_order = '1';
			$t_porperties_value_id = '';
			$t_porperties_value_model = '';
			$t_porperties_value_price = '0.00';
			$t_porperties_value_price_type = 'plus';
			$t_value_in_combis_count = 0;
		}else{
			$t_propertie_value = Array();
			#get data array for assigning in smarty template
			$t_content_data_array = $this->v_coo_properties_admin_control->get_properties_full_struct($c_properties_id, $c_language_id);
			foreach($t_content_data_array['PROPERTIES_VALUES'] AS $properties_values_key => $properties_values_value){
				if($properties_values_value['properties_values_id'] == $c_properties_values_id){
					$t_propertie_value = $properties_values_value;
					$t_propertie_value_names_array = $properties_values_value['VALUES_DESCRIPTIONS'];
					$t_sort_order = $properties_values_value['sort_order'];
					$t_porperties_value_model = $properties_values_value['value_model'];
					$t_porperties_value_price = number_format($properties_values_value['value_price'], 2);
					$t_porperties_value_price_type = $properties_values_value['value_price_type'];
					$t_value_in_combis_count = $this->v_coo_properties_admin_control->get_value_in_combis_count($c_properties_id, $c_properties_values_id);
				}
			}
		}
				
		
		$t_languages_array = xtc_get_languages();
		$t_properties_values_names_fields_array = array();
		
		# merge language_array with (maybe empty) names_array
		for($i=0; $i<sizeof($t_languages_array); $i++)
		{
			$t_properties_values_name = '';
			foreach($t_propertie_value_names_array AS $t_properties_language_array_item){                            
				if($t_languages_array[$i]['id'] ==  $t_properties_language_array_item['language_id']){
                                    $t_properties_values_name = $t_properties_language_array_item['name'];
				}
			}
			$t_properties_values_names_fields_array[] = array_merge(
																	$t_languages_array[$i],
																	array('properties_values_name' => $t_properties_values_name)
																);
		}
		
		$t_content_data_array = array(
									'PROPERTIES_VALUES_NAMES' => $t_properties_values_names_fields_array,
									'sort_order' => $t_sort_order,
									'properties_values_id' => $c_properties_values_id,
									'value_model' => $t_porperties_value_model,
									'value_price' => $t_porperties_value_price,
									'value_price_type' => $t_porperties_value_price_type,
									'value_in_combis_count' => $t_value_in_combis_count
								);
		
		$this->set_content_data("properties_values_data", $t_content_data_array);
                
		$t_html_output = $this->build_html();
		return $t_html_output;
	}
}
?>